import tornado.websocket
import tornado.web
import tornado.ioloop
import subprocess


class WebSocketHandler(tornado.websocket.WebSocketHandler):
    def open(self):
        print("WebSocket opened")

    def on_message(self, message):
        print("Received message:", message)
        data = json.loads(message)
        result = {
            'status': 'success',
            'message': 'hello world',
        }
        self.write_message(json.dumps(result))
        # 在此处添加你的Python代码来处理消息
        # 你可以在这里添加你的Python文件路径和其他参数
        print("hw")

    def on_close(self):
        print("WebSocket closed")

    def on_message(self, message):
        subprocess.run(["python", "E:\answer\main.py"])


app = tornado.web.Application([(r"/", WebSocketHandler)])
app.listen(3644)
tornado.ioloop.IOLoop.current().start()
